#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<unordered_map>
#include<stack>
#include<queue>
const int N = 1e5 + 9;
using namespace std;


int pre[N], rnk[N];

int root(int a)
{
    int res = a;
    while (res ^ pre[res]) res = pre[res];
    while (a != pre[a])
    {
        int b = a;
        a = pre[a];
        pre[b] = res;
    }
    return res;
}

void merge(int a, int b)
{
    int x = root(a), y = root(b);
    if (x == y) return;
    if (rnk[x] > rnk[y])
    {
        swap(x, y);
    }
    pre[x] = y;
    if (rnk[x] == rnk[y]) ++ rnk[x];
}

void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        pre[i] = i;
    }
    while (m--)
    {
        int op, a, b;
        cin >> op >> a >> b;
        if (op == 1) merge(a, b);
        else
        {
            cout << (root(a) == root(b) ? 'Y' : 'N') << endl;
        }
    }
}

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
    
};

class Solution {
public:
    long long pre = LLONG_MIN;
    bool isValidBST(TreeNode* root) {
        if (root == nullptr) return true;
        bool left = isValidBST(root->left);
        if (!left) return false;

        if (root->val <= pre) {
            return false;
        }
        else {
            pre = root->val;
        }
        return isValidBST(root->right);
    }

    bool isCompleteTree(TreeNode* root) {
        if (!root) return false;

        bool leaf = false;

        queue<TreeNode*> Q;
        Q.push(root);
        while (!Q.empty()) {
            TreeNode* front = Q.front();
            Q.pop();
            TreeNode* left = front->left;
            TreeNode* right = front->right;
            if (
                (leaf && (left || right))
                ||
                (!left && right)) return false;
            if (left) Q.push(left);
            if (right) Q.push(right);
            if (!left || !right) leaf = true;
        }
        return true;
    }
};

int main()
{
    solve();
    return 0;
}